﻿namespace ExamV5.WAPPage
{
    using ExamV5;
    using System;
    using System.Configuration;
    using System.Data;
    using System.Data.SqlClient;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;

    public class FrmGradeList : Page
    {
        protected Button butQuery;
        protected GridView DataGridInfo;
        protected DropDownList DDLQuery;
        protected HtmlForm form1;
        protected HtmlHead Head1;
        private HttpCookie httpCookie_0 = null;
        private HttpCookie httpCookie_1 = null;
        private HttpCookie httpCookie_2 = null;
        private HttpCookie httpCookie_3 = null;
        protected ImageButton ImgButExit;
        private PublicFun publicFun_0 = new PublicFun();
        protected ScriptManager SM;
        protected TextBox txtEndDate;
        protected TextBox txtQuery;
        protected TextBox txtStartDate;
        protected UpdatePanel UPPart;

        protected void butQuery_Click(object sender, EventArgs e)
        {
            this.DataGridInfo.PageIndex = 0;
            this.method_0();
        }

        protected void DataGridInfo_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            this.DataGridInfo.PageIndex = e.NewPageIndex;
            this.method_0();
        }

        protected void DataGridInfo_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.DataItemIndex == -1)
            {
                this.DataGridInfo.Attributes.Add("oldValue", "#FFFFFF");
                this.DataGridInfo.Attributes.Add("singleValue", "#FFFFFF");
            }
            else
            {
                e.Row.Attributes.Add("onmouseover", "this.bgColor='#F6F5F5'");
                if ((e.Row.DataItemIndex % 2) == 0)
                {
                    e.Row.Attributes.Add("bgcolor", "#FFFFFF");
                    e.Row.Attributes.Add("onmouseout", "this.bgColor=document.getElementById('DataGridInfo').getAttribute('singleValue')");
                }
                else
                {
                    e.Row.Attributes.Add("bgcolor", "#FFFFFF");
                    e.Row.Attributes.Add("onmouseout", "this.bgColor=document.getElementById('DataGridInfo').getAttribute('oldValue')");
                }
            }
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                if (e.Row.Cells[2].Text.Length > 10)
                {
                    e.Row.Cells[2].Text = "<a href='FrmShowUserExam.aspx?UserCode=" + base.Server.UrlEncode(e.Row.Cells[0].Text) + "&ID=" + this.DataGridInfo.DataKeys[e.Row.RowIndex]["PaperID"].ToString() + "' title=" + e.Row.Cells[2].Text + ">" + e.Row.Cells[2].Text.Substring(0, 10) + "…</a>";
                }
                else
                {
                    e.Row.Cells[2].Text = "<a href='FrmShowUserExam.aspx?UserCode=" + base.Server.UrlEncode(e.Row.Cells[0].Text) + "&ID=" + this.DataGridInfo.DataKeys[e.Row.RowIndex]["PaperID"].ToString() + "' title=" + e.Row.Cells[2].Text + ">" + e.Row.Cells[2].Text + "</a>";
                }
            }
            if (e.Row.RowType == DataControlRowType.Header)
            {
                string str;
                if (!(this.ViewState["SortType"].ToString() == " Desc"))
                {
                    str = this.ViewState["SortFiled"].ToString();
                    if (str != null)
                    {
                        if (str == "UserCode")
                        {
                            e.Row.Cells[0].Controls.Add(new LiteralControl("↓"));
                            return;
                        }
                        if (str == "UserName")
                        {
                            e.Row.Cells[1].Controls.Add(new LiteralControl("↓"));
                            return;
                        }
                        if (str == "ExamName")
                        {
                            e.Row.Cells[2].Controls.Add(new LiteralControl("↓"));
                            return;
                        }
                        if (str == "GetCountFen")
                        {
                            e.Row.Cells[3].Controls.Add(new LiteralControl("↓"));
                            return;
                        }
                    }
                    e.Row.Cells[2].Controls.Add(new LiteralControl("↓"));
                    return;
                }
                str = this.ViewState["SortFiled"].ToString();
                switch (str)
                {
                    case null:
                        goto Label_0402;

                    case "UserCode":
                        e.Row.Cells[0].Controls.Add(new LiteralControl("↑"));
                        return;

                    case "UserName":
                        e.Row.Cells[1].Controls.Add(new LiteralControl("↑"));
                        break;
                }
                if (str == "UserName")
                {
                    e.Row.Cells[1].Controls.Add(new LiteralControl("↑"));
                }
                else if (!(str == "ExamName"))
                {
                    if (!(str == "GetCountFen"))
                    {
                        goto Label_0402;
                    }
                    e.Row.Cells[3].Controls.Add(new LiteralControl("↑"));
                }
                else
                {
                    e.Row.Cells[2].Controls.Add(new LiteralControl("↑"));
                }
            }
            return;
        Label_0402:
            e.Row.Cells[2].Controls.Add(new LiteralControl("↑"));
        }

        protected void DataGridInfo_Sorting(object sender, GridViewSortEventArgs e)
        {
            string sortExpression = e.SortExpression;
            if (this.ViewState["SortFiled"].ToString() == sortExpression)
            {
                if (!(this.ViewState["SortType"].ToString() == " Desc"))
                {
                    this.ViewState["SortType"] = " Desc";
                }
                else
                {
                    this.ViewState["SortType"] = " ASC";
                }
            }
            else
            {
                this.ViewState["SortFiled"] = e.SortExpression;
            }
            this.method_0();
        }

        protected void ImgButExit_Click(object sender, ImageClickEventArgs e)
        {
            base.Response.Cookies["ExamUserCode"].Value = "";
            base.Response.Cookies["ExamUserName"].Value = "";
            base.Response.Cookies["ExamDeptName"].Value = "";
            base.Response.Cookies["ExamDeptID"].Value = "";
            base.Response.Cookies["ExamWorker"].Value = "";
            base.Response.Cookies["ExamUserSex"].Value = "";
            base.Response.Cookies["ExamUserLevel"].Value = "";
            base.Response.Cookies["ExamUserGWName"].Value = "";
            base.Response.Cookies["ExamUserGWLevel"].Value = "";
            string str = base.Request.Url.ToString();
            str = str.Substring(0, str.LastIndexOf('/') + 1);
            base.Response.Redirect(str + "FrmLogin.aspx");
        }

        private void method_0()
        {
            string selectCommandText = "";
            selectCommandText = "select d.ExamTime,(d.ExamTime-a.LastTime) as ExamUseTime,a.StartTime,a.EndTime,b.UserName,c.DeptName,a.UserCode,a.PaperID,a.ExamName,a.Subject,ROUND(a.GetOldCountFen,2) as GetOldCountFen,ROUND(a.GetCountFen,2) as GetCountFen,Flag=case a.Flag when 'C' then '考试完成' when 'D' then '客观题批改完成' when 'E' then '考试批改完成' when 'G' then '考试异常'  when 'Z' then '作弊标记' end  from ExamUser a,UserInfo b,DeptInfo c,PaperInfo d where d.ID=a.PaperID and a.UserCode=b.UserCode and b.DeptID=c.ID and (a.Flag<>'A' and a.Flag<>'B') ";
            if (!(this.publicFun_0.GetValues("select ParmValue from SysParmInfo where ParmMemo='IsLookTestExam'", "ParmValue").Trim() == "Y"))
            {
                selectCommandText = selectCommandText + " and  a.ExamType='A' ";
            }
            else
            {
                selectCommandText = selectCommandText + " and  (a.ExamType='A' or a.ExamType='C') ";
            }
            if (this.txtQuery.Text.Trim() != "")
            {
                selectCommandText = selectCommandText + " and " + this.publicFun_0.CheckString(this.DDLQuery.SelectedItem.Value) + " like '%" + this.publicFun_0.CheckString(this.txtQuery.Text) + "%'";
            }
            if (this.txtStartDate.Text.Trim() != "")
            {
                selectCommandText = selectCommandText + " and Convert(dateTime,a.JoinDate)>=Convert(dateTime,'" + this.publicFun_0.CheckString(this.txtStartDate.Text.Trim()) + " 00:00:00')";
            }
            if (this.txtEndDate.Text.Trim() != "")
            {
                selectCommandText = selectCommandText + " and Convert(dateTime,'" + this.publicFun_0.CheckString(this.txtEndDate.Text.Trim()) + " 23:59:59')>=Convert(dateTime,a.JoinDate)";
            }
            if (this.httpCookie_2.Value == "A")
            {
                selectCommandText = selectCommandText + " and a.UserCode='" + this.httpCookie_0.Value + "'";
            }
            selectCommandText = selectCommandText + "  order by a.PaperID desc," + this.ViewState["SortFiled"].ToString() + this.ViewState["SortType"].ToString();
            SqlConnection selectConnection = new SqlConnection(ConfigurationManager.ConnectionStrings["Conn"].ConnectionString);
            SqlDataAdapter adapter = new SqlDataAdapter(selectCommandText, selectConnection);
            DataSet dataSet = new DataSet();
            adapter.Fill(dataSet, "DataInfo");
            this.DataGridInfo.DataSource = dataSet.Tables["DataInfo"].DefaultView;
            this.DataGridInfo.DataBind();
            adapter.Dispose();
            selectConnection.Close();
            selectConnection.Dispose();
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            this.httpCookie_0 = new HttpCookie("ExamUserCode");
            this.httpCookie_0 = base.Request.Cookies["ExamUserCode"];
            this.httpCookie_1 = new HttpCookie("ExamUserName");
            this.httpCookie_1 = base.Request.Cookies["ExamUserName"];
            this.httpCookie_2 = new HttpCookie("ExamUserLevel");
            this.httpCookie_2 = base.Request.Cookies["ExamUserLevel"];
            this.httpCookie_3 = new HttpCookie("ExamDeptID");
            this.httpCookie_3 = base.Request.Cookies["ExamDeptID"];
            if ((this.httpCookie_0 != null) ? !(this.httpCookie_0.Value == "") : false)
            {
                base.Response.Cache.SetCacheability(HttpCacheability.NoCache);
                base.Response.Cache.SetNoStore();
                this.httpCookie_0.Value = this.publicFun_0.CheckString(base.Server.UrlDecode(this.httpCookie_0.Value));
                this.httpCookie_1.Value = this.publicFun_0.CheckString(base.Server.UrlDecode(this.httpCookie_1.Value));
                this.httpCookie_2.Value = this.publicFun_0.CheckString(base.Server.UrlDecode(this.httpCookie_2.Value));
                this.httpCookie_3.Value = this.publicFun_0.CheckString(base.Server.UrlDecode(this.httpCookie_3.Value));
                if (!base.IsPostBack)
                {
                    if (!(this.publicFun_0.ReturnPaperData() != "Yes"))
                    {
                        this.ViewState["SortFiled"] = "GetCountFen";
                        this.ViewState["SortType"] = " Desc";
                        this.method_0();
                    }
                    else
                    {
                        ScriptManager.RegisterStartupScript(this.UPPart, this.Page.GetType(), "BCheck", "alert('此版本暂未授权,请拔打(0)13870606104手机号进行授权！')", true);
                    }
                }
            }
            else
            {
                base.Response.Write("<script language=javascript>top.location.href='../Index.htm';self.close();</script>");
            }
        }
    }
}

